<template>
  <div>
    <QueryForm
      v-model="filters"
      :query-form-config="queryFormConfig"
      @handleQuery="handleQuery"
      @clear="clear"
    />
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-table doumee-element-tableb"
    >
      <el-table-column
        align="center"
        :label="translate('xfdh')"
        prop="businessId"
        min-width="220"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="translate('memberInfo')"
        prop="member"
        min-width="180"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="translate('xflx')"
        prop="businessName"
        min-width="80"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="translate('szlx')"
        min-width="80"
        prop="type"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <span v-if="scope.row.type == '0'">{{ translate("sr") }}</span>
          <span v-if="scope.row.type == '1'" class="secondColor">{{
            translate("zhichu")
          }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column
            align="center"
            label="收支金额"
            prop="money"
            min-width="200"
          /> -->
      <el-table-column
        align="center"
        :label="translate('czje')"
        prop="rechargeMoney"
        min-width="80"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <span v-if="scope.row.type == '0'">{{
            scope.row.rechargeMoney
          }}</span>
          <template v-if="scope.row.type == '1'">
            <span
              v-if="scope.row.rechargeMoney > 0"
              class="secondColor"
            >- {{ scope.row.rechargeMoney }}</span>
            <span v-else>{{ scope.row.rechargeMoney }}</span>
          </template>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="translate('giveMoney')"
        prop="giveMoney"
        min-width="80"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <span v-if="scope.row.type == '0'">{{ scope.row.giveMoney }}</span>
          <template v-if="scope.row.type == '1'">
            <span
              v-if="scope.row.giveMoney > 0"
              class="secondColor"
            >- {{ scope.row.giveMoney }}</span>
            <span v-else>{{ scope.row.giveMoney }}</span>
          </template>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="translate('czye')"
        prop="afterRecharge"
        min-width="80"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="translate('zsye')"
        prop="afterGive"
        min-width="80"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="translate('xfcg')"
        prop="venueName"
        min-width="120"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="translate('xfsj')"
        prop="createTime"
        min-width="160"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="translate('operator')"
        prop="creator"
        min-width="100"
        show-overflow-tooltip
      />
    </el-table>
    <Paginations
      :total="totalCount"
      :page="pagination.page"
      @current-change="currentChange"
      @SizeChange="handleSizeChange"
    />
  </div>
</template>

<script>
import { queryFormConfig } from './config'
import QueryForm from '@/components/QueryForm'
import { consumeAllRecord, configList, orderTypeList } from '@/api'
export default {
  components: {
    QueryForm
  },
  data() {
    return {
      queryFormConfig,
      filters: {
        venueId: sessionStorage.getItem('venueId')
      },
      pagination: {
        rows: 10,
        page: 1
      },
      list: [],
      totalCount: 0,
      listLoading: false
    }
  },
  created() {
    this.getList()
    this.QueryOrderType()
    // this.initOptions()
  },
  mounted() {
    this.$refs.table.doLayout()
  },
  methods: {
    QueryOrderType() {
      orderTypeList({ param: { type: 'ORDER_TYPE_CONFIG' }}).then(res => {
        this.queryFormConfig.formItems[1].options = res.recordList || []
      })
    },
    handleQuery() {
      this.pagination.page = 1
      this.getList()
    },
    currentChange(val) {
      this.pagination.page = val
      this.getList()
    },
    initOptions() {
      configList({ param: { type: 2, code: 'PAY_CONFIG' }}).then(res => {
        const temp = res.recordList.map(i => {
          i.label = i.name
          return i
        })
        this.queryFormConfig.formItems[2].options = temp
      })
    },
    handleSizeChange(val) {
      this.pagination.rows = val
      this.getList()
    },
    getList() {
      const { filters, pagination } = this
      const parma = JSON.parse(JSON.stringify(filters))
      if (parma.code) {
        parma.businessCodes = [filters.code]
      } else {
        parma.businessCodes = []
      }
      const data = {
        param: parma,
        pagination: pagination
      }
      this.listLoading = true
      consumeAllRecord(data).then(res => {
        this.listLoading = false
        this.list = res.recordList
        this.totalCount = res.totalCount
      }, () => {
        this.listLoading = false
      })
    },
    clear() {
      this.filters = {
        venueId: sessionStorage.getItem('venueId')
      }
      this.handleQuery()
    }
  }
}
</script>

<style>
</style>
